//GrepReader.java
package decorator.halfClear.grep;

import java.io.*;

/**
 * GrepReader is a half visible decorator for FileReader.
 * It expands the FileReader's abilities.
 *@author:youtubezou
 *@version:2012-7-18
 */
public class GrepReader extends FilterReader {
	protected String substr;
	protected BufferedReader in;
	private int lineNumber;
	
	protected GrepReader(FileReader in, String substr) {
		super(in);
		this.in = new BufferedReader(in);
		this.substr =substr;
		lineNumber = 0;
	}
	
	public String readLine() throws IOException{
		String line;
		
		do{
			line = in.readLine();
			if(line == null)
				break;
			lineNumber++;
		} while (line.indexOf(substr) == -1);
		
		return line;
	}
	
	public int getLineNo(){
		return lineNumber;
	}
	
	
}
